<title>管理员管理 - 权限管理 - {$cfg_website}</title>
<meta name="keywords" content="{$cfg_keywords?:''}">
<meta name="description" content="{$cfg_description?:''}">
<link rel="stylesheet" href="__STATIC__/lib/zTree/v3/css/metroStyle/metroStyle.css">{include file="public_tpl/head"/}
</head>
<body>
<!--面包屑-->
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 管理员管理
    <span class="c-gray en">&gt;</span> 权限管理
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<!--/面包屑-->

<div class="page-container">
    <form action="{:url('access')}" method="post">
        <ul id="treeDemo" class="ztree"></ul>
        <input id="smt-btn" class="btn btn-primary radius" type="button " value="提交">
    </form>

</div>
{include file="public_tpl/script"/}
<script src="__STATIC__/lib/zTree/v3/js/jquery.ztree.all-3.5.js"></script>
<script>
    var zTreeObj;
    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
    var setting = {
        data: {
            key: {
                children: "child"
            },
            simpleData: {
                enable: true
            }
        },
        check: {
            autoCheckTrigger: true,
            enable: true,
            chkStyle: "checkbox",
            chkboxType: {"Y": "p", "N": "s"}
        },
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "pid",
            rootPId: 0
        },
        view: {
            selectedMulti: true
        }
    };
    // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
    var zNodes = {$tree|json_encode};
    $(document).ready(function () {
        zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);

        function onCheck() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo"), nodes = treeObj
                .getCheckedNodes(true), v = [];
            for (var i = 0; i < nodes.length; i++) {
                v.push(nodes[i].id);
            }
            console.log(v);
            return v;
        }

        $("#smt-btn").click(function () {
            var access = onCheck();
            var roleId = $("input[name='roleId']").val();
            var url = "{:url('access')}";
            $.post(url, {id: {$id}, access: access.join(",")}, function (data) {
                if (data.code) {
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        location.href = data.url;
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 2000})
                }
            })
        });
    });
</script>
</body>
</html>